class Solution:
    def longestOnes(self, nums: List[int], k: int) -> int:
        left = 0
        n = len(nums)
        res = -1
        t = 0
        for right,num in enumerate(nums):
            if num == 0:
                t+=1
            while t > k:
                if nums[left] == 0:
                    t -=1
                left+=1
            res = max(res,right-left+1)
        return res